package com.sf.adapter;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sf.bean.NumDefineItem;
import com.sf.pathmemorymethod.PileEditActivity;
import com.sf.pathmemorymethod.R;
import com.sf.util.Path;

import java.util.List;

/**
 * Created by liutaigang on 2018/7/7.
 */

public class NumDefineAdapter extends BaseAdapter {

    private Context context;   //运行上下文
    private List<NumDefineItem> mData;    //路径集合
    private LayoutInflater mInflater;   //视图容器

    public NumDefineAdapter(Context context,List<NumDefineItem> mData){
        this.context = context;
        this.mData = mData;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private final class ViewHolder{
        private int id;
        private TextView number;
        private TextView description;
        private ImageView img;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final NumDefineItem numDefineItem = mData.get(position);

        ViewHolder holder = null;

        if(convertView == null){
            convertView = mInflater.inflate(R.layout.layout_num_define_item, null);
            holder = new ViewHolder();
            holder.id = numDefineItem.getId();
            holder.number = (TextView)convertView.findViewById(R.id.item_num_define_number);
            holder.description = (TextView) convertView.findViewById(R.id.item_num_define_description);
            holder.img = (ImageView) convertView.findViewById(R.id.item_num_define_icon);

            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        holder.id = numDefineItem.getId();
        holder.number.setText(numDefineItem.getNumber());
        holder.description.setText(numDefineItem.getDescription());

        convertView.setId(numDefineItem.getId());

        return convertView;
    }
}
